<?php
/*
 * 手机客户端店铺-获得订单信息接口
 * 2014-03-19
 * 2014-05-08 (已查) 
 */
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数


$reJson = array(); //构建返回值

$orderId = $_REQUEST["orderId"];

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"];//用户信息主键


$sql = "select b.product_name,b.shangjia,b.quantity,b.salesvolume,c.tcount from shop_order a INNER JOIN shop_order_detail c on a.id=c.pid INNER JOIN shop_product b on c.product_id=b.product_id where a.id='".$orderId."'";
$db->query($sql);
while($db->next_record()){
	if (($db->f("quantity"))-($db->f("salesvolume"))<$db->f("tcount")){
		$list1[]=$db->f("product_name");
	}
	if ($db->f("shangjia")=="0"){
		$list2[]=$db->f("product_name");
	}
}
if ($list2){
	echo json_encode(array("success"=>"0","errCode"=>"2","msg"=>"商品已下架","list"=>$list2));
	die;
}else if ($list1){
	echo json_encode(array("success"=>"0","errCode"=>"1","msg"=>"商品库存不足","list"=>$list1));
	die;
}

//商品介绍信息
$sql = "SELECT tprice,shop_id,ctime,yunfei,ship_man,ship_address,ship_pcode,ship_mobile from shop_order where id='".$orderId."'"; 
$db->query($sql);
if($db->next_record()){
	$tprice	 = $db->f("tprice")+$db->f("yunfei");
	$shop_id = $db->f("shop_id");
	$ctime = $db->f("ctime");
	$ship_man = $db->f("ship_man");
	$ship_address = $db->f("ship_address");
	$ship_pcode = $db->f("ship_pcode");
	$ship_mobile = $db->f("ship_mobile");
}
if ($ship_man){
$address = array();
$address = array(
		"name"=>$ship_man
		,"province"=>""
		,"city"=>""
		,"county"=>""
		,"detailAddress"=>$ship_address
		,"postCode"=>$ship_pcode
		,"mobile"=>$ship_mobile
		,"phone"=>""
	);

}
$remark = "";
if ($shop_id=="81" or $shop_id=="86" or $shop_id=="87" or $shop_id=="88" or $shop_id=="92" or $shop_id=="93"){
	$remark = "预付款";
}
$tids = $orderId.";";
$sql = "SELECT rno from chinapay_running_number where order_id='".$tids."'"; 
$db->query($sql);
if($db->next_record()){
	$rno = $db->f("rno");
}else{
$orderTime = date('Y-m-d H:i:s', time());
$rno = str_replace(array('-',':',' '), '', $orderTime);
$sql="insert into chinapay_running_number (rno,order_id) values ('".$rno."','".$tids."')";
$db->query($sql);
}
$reJson["success"] = "1";
$reJson["orderNum"] = $rno;
$reJson["orderTime"] = $ctime;
$reJson["address"] = $address;
$payType[] = array(
		"key"=>"1"			
		,"value"=>"银联移动支付"		
	);
$payType[] = array(
		"key"=>"2"			
		,"value"=>"线下银行支付"		
	);

$reJson["package"] = "1";
$reJson["payType"] = $payType;
$reJson["pay"] = "$tprice";
$reJson["remark"] = $remark;
echo json_encode($reJson);
?>
